package com.example.service.impl;

import com.example.mapp.StatisticsMapp;
import com.example.service.SelfStatisticService;
import com.example.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by simon on 2018/11/28.
 */
@Service
public class SelfStatisticServiceImpl implements SelfStatisticService {
    private final static Logger logger = (Logger) LoggerFactory.getLogger(SelfStatisticServiceImpl.class);
    @Autowired
    StatisticsMapp statisticsMapp;

    @Override
    public Map<String, Object> selfCount(String sql) {
        Map<String, Object> map = new HashMap<String, Object>();
        try{
            List res = statisticsMapp.selfCount(sql);
            map.put("list",res);
            return ResultUtil.returnSuccess("成功",map);
        }catch(Exception e){
            logger.error("通过sql 查询统计失败！", e);
            return ResultUtil.returnError("查询失败了，确定你的sql语句正确？",null);
        }
    }
}
